package com.yh.controller;

import com.opensymphony.xwork2.ModelDriven;
import com.yh.entity.Books;
import com.yh.services.IBookService;
import com.yh.services.impl.BookServiceImpl;
import com.yh.util.BaseAction;
import lombok.Data;
import net.sf.json.JSONArray;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@Data
public class BookAction extends BaseAction{
    private String sou;

    IBookService ibs=new BookServiceImpl();
    JSONArray jsonArray = new JSONArray();

    public String showAllByBname() throws IOException {
        PrintWriter out=getResponse().getWriter();
        List<Books> list=ibs.showAllByBname(sou);
        if (list.size() > 0) {
            jsonArray.addAll(list);
        }
        out.print(jsonArray);
        return null;
    }

    public String showAllByAuthor() throws IOException {
        PrintWriter out=getResponse().getWriter();
        List<Books> list=ibs.showAllByAuthor(sou);
        if (list.size() > 0) {
            jsonArray.addAll(list);
        }
        out.print(jsonArray);
        return null;
    }

    public String showAllByPubl() throws IOException {
        PrintWriter out=getResponse().getWriter();
        List<Books> list=ibs.showAllByPubl(sou);
        if (list.size() > 0) {
            jsonArray.addAll(list);
        }
        out.print(jsonArray);
        return null;
    }

}
